<?php 
class News extends Module {
    //public $typename = 'news';
    /*
    private $published;
    private $expired;
    private $content;
    */
    
    /*
    protected function add_content_view () {
        return $this->view('news_content');
    }*/
    
    /*public function get_title() {
        return 'Add News';
    }*/
    
    public function add_content_data($node_id) {
        $node_id = trim($node_id);
        if (empty($node_id)) {
            return false;
        }
        
        $published = tos_http_post('published');
        $expired = tos_http_post('expired');
        $content = tos_http_post('content');
        
        if (empty($content)) {
            return false;
        }
        
        if (empty($published)) {
            $published = time();
        } else {
            $published = strtotime($published);
        }
        
        if (empty($expired)) {
            $expired = time();
        } else {
            $expired = strtotime($expired);
        }
        
        return $this->model('news')->add($node_id, $published, $expired, $content);
    }
    
    public function edit_content_data($node_id) {
        $node_id = (int) $node_id;
        if ($node_id <= 0) {
            tos_die('edit content data no node id');
        }
        
        $published = tos_http_post('published');
        $expired = tos_http_post('expired');
        $content = tos_http_post('content');
        
        return $this->model('news')->add($node_id, $published, $expired, $content);
    }
    
    public function display_content($node_id) {
        if ($content_data = $this->model('news')->entry($node_id)) {
            return $this->view('news_display', $content_data);
        } else {
            return false;
        }
        
    }
    public function display_content_edit($node_id) {
        if ($content_data = $this->model('news')->entry($node_id)) {
            return $this->view('news_edit', $content_data);
        } else {
            return false;
        }
    }
    
    public function display_content_add() {
        return $this->view("news_edit");
    }
    
    public function get_description() {
        $content = tos_http_post('content');
        if ( ! empty($content)) {
            return tos_html_strip($content);
        } 
        return '';
    }
}
?>